package com.jin.webvideo.videoCache;

import com.jin.webvideo.util.cloneUtil.Cloneable;

import java.util.HashMap;
import java.util.Map;
@Cloneable
public class SegmentParam {
    private static String template = "%s=%s,";
    private static String templateEmpty = "%s,";
    private String name;
    private Map<String, String> values;
    public SegmentParam(){
        this.values = new HashMap<>();
    }
    public Map<String, String> getValues() {
        return values;
    }

    public void setValues(Map<String, String> values) {
        this.values = values;
    }
    public void putValue(String key, String value) {
        this.values.put(key, value);
    }
    public String getValue(String key) {
        return values.get(key);
    }
    public String getStingValue() {
        if (values.size() == 0){
            return null;
        }
        StringBuilder builder = new StringBuilder();
        for (String key : values.keySet()){
            String temp = template;
            String value = getValue(key);
            if (null == value){
                temp = templateEmpty;
            }
            builder.append(String.format(temp, key, value));
        }
        if (builder.length() == 0){
            return "";
        }
        return builder.substring(0, builder.length()-1);
    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name.trim();
    }
}
